package com.session01;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

public class StringDemo {
    public static void main(String[] args) {
        testString();

        testStr();

        testDate();

        testDate2();
    }

    public static void testString() {
        String s1 = "xiaojichao";
        String s2 = new String("xiaojichao");
        System.out.println(s1 == s2);

        String s3 = "abc";
        String s4 = "abc";
        System.out.println(s3 == s4);

        String s5 = new String("abc");
        String s6 = new String("abc");
        System.out.println(s5 == s6);

        String s7 = new String("hello") + new String("world");
        String s8 = "helloworld";
        System.out.println(s7 == s8);
    }

    public static void testStr() {
        String s1 = new String("hello") + new String("world");
        String s2 = new String("helloworld");
        System.out.println(s1 == s2);
    }

    public static void testDate() {
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDateTime);

        LocalDate localDate = LocalDate.now();
        System.out.println(localDate);

        LocalTime localTime = LocalTime.now();
        System.out.println(localTime);

        LocalDate date = LocalDate.of(1998, 3, 17);
        System.out.println(date);
    }

    public static void testDate2() {
        LocalDateTime dateTime = LocalDateTime.now();
        System.out.println(dateTime.getYear());

        System.out.println(dateTime.plusDays(30));
        System.out.println(dateTime.minusDays(30));
        System.out.println(dateTime.getDayOfMonth());

        LocalDate nowDate = LocalDate.now();

        System.out.println("-----------------");
        String strDate= DateTimeFormatter.ofPattern("yyyy年MM月dd日").format(nowDate);
        System.out.println(strDate);
        System.out.println("-----------------");

        LocalDate birthday = LocalDate.of(1998, 3, 17);
        System.out.println(ChronoUnit.DAYS.between(birthday, nowDate));
    }
}
